package org.file5.service;

import org.file5.domain.BaseEntity;
import org.file5.domain.Entity2Entity;
import org.file5.domain.Entity2Entity.Relation;
import org.file5.util.DataBean;

import com.googlecode.objectify.Key;

public interface BaseService {

	/**
	 * Gets list of stored entities of the specified type. Not a good idea to
	 * use this for plentiful entities.
	 * 
	 * @param startPosition
	 * @param maxResult
	 * @return list of entities
	 */
	public <E extends BaseEntity> DataBean<E> getListBy(Class<E> entityClass, int startPosition,
			int maxResult);

	public <E extends BaseEntity, E2 extends BaseEntity> DataBean<Entity2Entity<E, E2> > getEntity2EntitiesBy(int startPosition,
			int maxResult, E entity,Entity2Entity.Relation relation, E2 entity2);
	public <E extends BaseEntity, E2 extends BaseEntity> DataBean<Entity2Entity<E, E2>> getEntity2EntitiesBy(
			int startPosition, int maxResult, Class<E> entityClass, String entityUid,
			Relation relation,Class<E2>entity2Class, String entity2Uid);
	public <E extends BaseEntity, E2 extends BaseEntity>  Entity2Entity<E, E2> findEntity2Entity(E entity,Entity2Entity.Relation relation,
			E2 entity2);
	/**
	 * Finds an entity by its Key.
	 * 
	 * @param id
	 * @return entity
	 */
//	public <E extends BaseEntity> E find(Class<E> entityClass, Key<E> key);
	public <E extends BaseEntity> E find( Key<E> key);

	/**
	 * Finds an entity by its uid
	 * 
	 * @param uid
	 * @return
	 */
	public <E extends BaseEntity> E find(Class<E> entityClass, String uid);

	/**
	 * Saves an entity into persistent storage
	 * 
	 * @param entity
	 * @return saved entity
	 */
	public <E extends BaseEntity> E addUpdate(E entity);

	/**
	 * Removes an entity
	 * 
	 * @param entity
	 */
	public <E extends BaseEntity> void remove(E entity);

	/**
	 * Removes an entity by its id
	 * 
	 * @param id
	 */
	public <E extends BaseEntity> void remove(Class<E> entityClass, Long id);

	public <E extends BaseEntity> E updateStatus(Class<E> entityClass, String uid,
			BaseEntity.STATUS entityStatus);

	public <E extends BaseEntity> void clearData(Class<E> entityClass);

}
